package com.aegean.MonitorExamSYS.examinee.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.aegean.MonitorExamSYS.examinee.business.ExamineeBusiness;
import com.aegean.MonitorExamSYS.examinee.component.ExamineeExam;
import com.aegean.MonitorExaxSYS.model.ExamineeValue;
import com.opensymphony.xwork2.ActionSupport;

@Controller("NavigationUserSearchExam")
@Scope("prototype")
public class NavigationUserSearchExam extends ActionSupport implements
		ServletRequestAware {
	@Resource
	ExamineeBusiness business;
	private int pageNow;// 当前页
	private int totalRows;// 总条例个数
	private int pageCount;// 页数
	private int start;
	private int limit;
	private HttpServletRequest request;
	private HttpSession session;
	public List<ExamineeExam> getExs() {
		return exs;
	}

	public void setExs(List<ExamineeExam> exs) {
		this.exs = exs;
	}

	private List<ExamineeExam> exs;

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public int getPageNow() {
		return pageNow;
	}

	public void setPageNow(int pageNow) {
		this.pageNow = pageNow;
	}

	public int getTotalRows() {
		return totalRows;
	}

	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		limit = 15;
		ExamineeValue one = (ExamineeValue) session.getAttribute("UserLogin");
		totalRows = business.showExamineeQualifications(one.getUser_Id(),"(0,3)");
		if ((totalRows % limit) == 0) {
			pageCount = totalRows / limit;
		} else {
			pageCount = totalRows / limit + 1;
		}
		if (pageNow > pageCount) {
			pageNow = pageCount;
		} else if (pageNow < 1) {
			pageNow = 1;
		}
		start = (pageNow - 1) * limit;
		exs = business.showExamineeQualificationsList(one.getUser_Id(), start,
				limit,"(0,3)");
		return SUCCESS;
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		this.request = arg0;
		this.session = request.getSession();
	}
    
	public String position()  throws Exception{
		ExamineeValue one = (ExamineeValue) session.getAttribute("UserLogin");
		totalRows = business.showExamineeQualifications(one.getUser_Id(),"(3)");
		exs = business.showExamineeQualificationsList(one.getUser_Id(), 0,
				totalRows,"(3)");
		return SUCCESS;
	}
}
